/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package logic.mapping;

import entityBeans.Interaction;
import entityBeans.Specimen;
import java.text.SimpleDateFormat;
import xlsBeans.InteractionXLS;
import xlsBeans.SpecimenXLS;

/**
 *
 * @author joao
 */
public class EntityToXLS {

       public EntityToXLS(){
       }

        public SpecimenXLS mapping(Specimen sp){
            SpecimenXLS xls = new SpecimenXLS();
            SimpleDateFormat sdf;
            //Main Field
            xls.getMain().setBasisofrecord(sp.getRecordlevelelement().getBasisofrecord().getBasisofrecord());
            xls.getMain().setInstitutioncode(sp.getRecordlevelelement().getInstitutioncode().getInstitutioncode());
            xls.getMain().setCollectioncode(sp.getRecordlevelelement().getCollectioncode().getCollectioncode());
            xls.getMain().setCatalognumber(sp.getOccurrenceelement().getCatalognumber());
            xls.getMain().setScientificname(sp.getTaxonomicelement().getScientificname().getScientificname());
            // Record-level Elements
            xls.getRec().setType(sp.getRecordlevelelement().getType().getType());
            xls.getRec().setOwnercode(sp.getRecordlevelelement().getOwnerinstitution().getOwnerinstitution());
            xls.getRec().setDataset(sp.getRecordlevelelement().getDataset().getDataset());
            xls.getRec().setRights(sp.getRecordlevelelement().getRights());
            xls.getRec().setRightsholder(sp.getRecordlevelelement().getRightsholder());
            xls.getRec().setAccessrights(sp.getRecordlevelelement().getAccessrights());
            xls.getRec().setInformationwithheld(sp.getRecordlevelelement().getInformationwithheld());
            xls.getRec().setDatageneralization(sp.getRecordlevelelement().getDatageneralization());
            xls.setPrivate1(sp.getRecordlevelelement().getIsrestricted());
            //nxn Dynamicproperty            
            xls.getRec().setDynamicproperties(sp.getRecordlevelelement().getDynamicpropertyList().get(0).getDynamicproperty());
            // Taxonomic Elements
            xls.getTax().setKingdom(sp.getTaxonomicelement().getKingdom().getKingdom());
            xls.getTax().setPhylum(sp.getTaxonomicelement().getPhylum().getPhylum());
            xls.getTax().setClasse(sp.getTaxonomicelement().getClass1().getClass1());
            xls.getTax().setOrder(sp.getTaxonomicelement().getOrder1().getOrder());
            xls.getTax().setFamily(sp.getTaxonomicelement().getFamily().getFamily());
            xls.getTax().setGenus(sp.getTaxonomicelement().getGenus().getGenus());
            xls.getTax().setSubgenus(sp.getTaxonomicelement().getSubgenus().getSubgenus());
            xls.getTax().setSpecificepithet(sp.getTaxonomicelement().getSpecificepithet().getSpecificepithet());
            xls.getTax().setInfraspecificepithet(sp.getTaxonomicelement().getInfraspecificepithet().getInfraspecificepithet());
            xls.getTax().setTaxonrank(sp.getTaxonomicelement().getTaxonrank().getTaxonrank());
            xls.getTax().setScientificnameauthor(sp.getTaxonomicelement().getScientificnameauthorship().getScientificnameauthorship());
            xls.getTax().setNomenclaturalcode(sp.getTaxonomicelement().getNomenclaturalcode().getNomenclaturalcode());
            xls.getTax().setTaxonconcept(sp.getTaxonomicelement().getTaxonconcept().getTaxonconcept());
            xls.getTax().setNomenclaturalstatus(sp.getTaxonomicelement().getNomenclaturalstatus());
            xls.getTax().setAcceptednameusage(sp.getTaxonomicelement().getAcceptednameusage().getAcceptednameusage());
            xls.getTax().setParentnameusage(sp.getTaxonomicelement().getParentnameusage().getParentnameusage());
            xls.getTax().setOriginalnameusage(sp.getTaxonomicelement().getOriginalnameusage().getOriginalnameusage());
            xls.getTax().setNameaccordingto(sp.getTaxonomicelement().getNameaccordingto().getNameaccordingto());
            xls.getTax().setNamepublishedin(sp.getTaxonomicelement().getNamepublishedin().getNamepublishedin());
            xls.getTax().setVernacularname(sp.getTaxonomicelement().getVernacularname());
            xls.getTax().setTaxonomicstatus(sp.getTaxonomicelement().getTaxonomicstatus().getTaxonomicstatus());
            xls.getTax().setVerbatimtaxonrank(sp.getTaxonomicelement().getVerbatimtaxonrank());
            xls.getTax().setTaxonremarks(sp.getTaxonomicelement().getTaxonremark());
            //Occurence Elements
            xls.getOcc().setIndividual(sp.getOccurrenceelement().getIndividualList().get(0).getIndividual());
            xls.getOcc().setIndividualcount(sp.getOccurrenceelement().getIndividualcount()==null?null:sp.getOccurrenceelement().getIndividualcount().doubleValue()); //double-int?
            xls.getOcc().setSex(sp.getOccurrenceelement().getSex().getSex());
            xls.getOcc().setBehavior(sp.getOccurrenceelement().getBehavior().getBehavior());
            xls.getOcc().setLifestage(sp.getOccurrenceelement().getLifestage().getLifestage());
            xls.getOcc().setDisposition(sp.getOccurrenceelement().getDisposition().getDisposition());
            xls.getOcc().setReproductivecondition(sp.getOccurrenceelement().getReproductivecondition().getReproductivecondition());
            xls.getOcc().setEstabilishmentmean(sp.getOccurrenceelement().getEstablishmentmean().getEstablishmentmean());
            //nxn Recordby
            xls.getOcc().setRecordedby(sp.getOccurrenceelement().getRecordedbyList().get(0).getRecordedby());
            xls.getOcc().setRecordnumber(sp.getOccurrenceelement().getRecordnumber());
            xls.getOcc().setOthercatalognumbers(sp.getOccurrenceelement().getOthercatalognumber());
            //nxn Preparation
            xls.getOcc().setPreparations(sp.getOccurrenceelement().getPreparationList().get(0).getPreparation());
            //nxn Associatedsequence
            xls.getOcc().setAssociatedsequences(sp.getOccurrenceelement().getAssociatedsequenceList().get(0).getAssociatedsequence());
            xls.getOcc().setOccurrencedetails(sp.getOccurrenceelement().getOccurrencedetail());
            xls.getOcc().setOccurrenceremarks(sp.getOccurrenceelement().getOccurrenceremark());
            xls.getOcc().setOccurrencestatus(sp.getOccurrenceelement().getOccurrencestatus());
            //Identification Elements

            if(sp.getIdentificationelement().getDateidentified() != null){
                sdf = new SimpleDateFormat();
                sdf.applyPattern("yyyy/MM/dd");
                xls.getId().setDateidentified(sdf.format(sp.getIdentificationelement().getDateidentified()));
            }
            xls.getId().setIdentificationqualifier(sp.getIdentificationelement().getIdentificationqualifier().getIdentificationqualifier());
            //nxn Identifiedby
            xls.getId().setIdentifiedby(sp.getIdentificationelement().getIdentifiedbyList().get(0).getIdentifiedby());
            //nxn Typestatus
            xls.getId().setTypestatus(sp.getIdentificationelement().getTypestatusList().get(0).getTypestatus());
            xls.getId().setIdentificationremarks(sp.getIdentificationelement().getIdentificationremark());
            //Event Elements
            xls.getEve().setSamplingprotocol(sp.getEventelement().getSamplingprotocol().getSamplingprotocol());
            xls.getEve().setSamplingeffort(sp.getEventelement().getSamplingeffort());
            xls.getEve().setHabitat(sp.getEventelement().getHabitat().getHabitat());
            xls.getEve().setVerbatimeventdate(sp.getEventelement().getVerbatimeventdate());
            if(sp.getEventelement().getEventtime() != null){
                sdf = new SimpleDateFormat();
                sdf.applyPattern("hh:mm:ss");
                xls.getEve().setEventtime(sdf.format(sp.getEventelement().getEventtime()));
            }
            if(sp.getEventelement().getEventdate() != null){
                sdf = new SimpleDateFormat();
                sdf.applyPattern("yyyy/MM/dd");
                xls.getEve().setEventdate(sdf.format(sp.getEventelement().getEventdate()));
            }
            xls.getEve().setFieldnumber(sp.getEventelement().getFieldnumber());
            xls.getEve().setFieldnotes(sp.getEventelement().getFieldnote());
            xls.getEve().setEventremarks(sp.getEventelement().getEventremark());
            //Locality Elements
            xls.getLoc().setContinent(sp.getLocalityelement().getContinent().getContinent());
            xls.getLoc().setCountry(sp.getLocalityelement().getCountry().getCountry());
            xls.getLoc().setStateorprovince(sp.getLocalityelement().getStateprovince().getStateprovince());
            xls.getLoc().setCounty(sp.getLocalityelement().getCounty().getCounty());
            xls.getLoc().setMunicipality(sp.getLocalityelement().getMunicipality().getMunicipality());
            xls.getLoc().setLocality(sp.getLocalityelement().getLocality().getLocality());
            xls.getLoc().setWaterbody(sp.getLocalityelement().getWaterbody().getWaterbody());
            xls.getLoc().setIslandgroup(sp.getLocalityelement().getIslandgroup().getIslandgroup());
            xls.getLoc().setIsland(sp.getLocalityelement().getIsland().getIsland());
            xls.getLoc().setLocationaccordingto(sp.getLocalityelement().getLocationaccordingto());
            xls.getLoc().setCoordinateprecision(sp.getLocalityelement().getCoordinateprecision());
            xls.getLoc().setLocationremarks(sp.getLocalityelement().getLocationremark());
            xls.getLoc().setMinimunelevation(sp.getLocalityelement().getMinimumelevationinmeters());
            xls.getLoc().setMaximumelevation(sp.getLocalityelement().getMaximumelevationinmeters());
            xls.getLoc().setMinimumdepth(sp.getLocalityelement().getMinimumdepthinmeters());
            xls.getLoc().setMaximumdepth(sp.getLocalityelement().getMaximumdepthinmeters());
            xls.getLoc().setMinimumdistance(sp.getLocalityelement().getMinimumdistanceabovesurfaceinmeters()==null?null:sp.getLocalityelement().getMinimumdistanceabovesurfaceinmeters().doubleValue());
            xls.getLoc().setMaximumdistance(sp.getLocalityelement().getMaximumdistanceabovesurfaceinmeters()==null?null:sp.getLocalityelement().getMaximumdistanceabovesurfaceinmeters().doubleValue());
            xls.getLoc().setVerbatimdepth(sp.getLocalityelement().getVerbatimdepth());
            xls.getLoc().setVerbatimelevation(sp.getLocalityelement().getVerbatimelevation());
            xls.getLoc().setVerbatimlocality(sp.getLocalityelement().getVerbatimlocality());
            xls.getLoc().setVerbatimsrs(sp.getLocalityelement().getVerbatimsrs());
            //nxn Georeferencedby
            xls.getLoc().setGeoreferencedby(sp.getLocalityelement().getGeoreferencedbyList().get(0).getGeoreferencedby());
            //nxn Georeferencesource
            xls.getLoc().setGeoreferencesources(sp.getLocalityelement().getGeoreferencesourceList().get(0).getGeoreferencesource());
            xls.getLoc().setFootprintsrs(sp.getLocalityelement().getFootprintsrs());
            //Geospatial Elements
            xls.getGeo().setDecimalaltitude(sp.getGeospatialelement().getDecimallatitude());
            xls.getGeo().setDecimallongitude(sp.getGeospatialelement().getDecimallongitude());
            xls.getGeo().setCoordinateuncertainty(sp.getGeospatialelement().getCoordinateuncertaintyinmeters());
            xls.getGeo().setGeodeticdatum(sp.getGeospatialelement().getGeodeticdatum());
            xls.getGeo().setPointradiusspatialfit(sp.getGeospatialelement().getPointradiusspatialfit());
            xls.getGeo().setVerbatimcoordinates(sp.getGeospatialelement().getVerbatimcoordinate());
            xls.getGeo().setVerbatimlatitude(sp.getGeospatialelement().getVerbatimlatitude());
            xls.getGeo().setVerbatimlongitude(sp.getGeospatialelement().getVerbatimlongitude());
            xls.getGeo().setVerbatimcoordinatesystem(sp.getGeospatialelement().getVerbatimcoordinatesystem());
            xls.getGeo().setGeoreferenceprotocol(sp.getGeospatialelement().getGeoreferenceprotocol());
            xls.getGeo().setVerificationstatus(sp.getGeospatialelement().getGeoreferenceverificationstatus().getGeoreferenceverificationstatus());
            xls.getGeo().setGeoreferenceremarks(sp.getGeospatialelement().getGeoreferenceremark());
            xls.getGeo().setFootprintwkt(sp.getGeospatialelement().getFootprintwkt());
            xls.getGeo().setFootprintspatialfit(sp.getGeospatialelement().getFootprintspatialfit());

            return xls;
        }

        public InteractionXLS mapping(Interaction inte){
            InteractionXLS xlsInt = new InteractionXLS();
            //Main Field
            xlsInt.setInteractioninformation(inte.getInteractionrelatedinformation());
            xlsInt.setInteractiontype(inte.getInteractiontype().getInteractiontype());
            return xlsInt;
        }
}
